﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// Action to create a new category
    /// </summary>
    public class CreateCategoryAction : UserActionBase
    {
        private CategoryViewModel createdCategory, parentCategory;
        private string createdCategoryName;

        /// <summary>
        /// Creates a new action to create a new category
        /// </summary>
        /// <param name="parent">The parent to create the category under</param>
        /// <param name="name">The name of the category</param>
        public CreateCategoryAction(CategoryViewModel parent, string name)
            : base()
        {
            parentCategory = parent;
            createdCategoryName = name;
        }

        /// <summary>
        /// Creates a new category
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            createdCategory = new CategoryViewModel(new Category(parentCategory.CategoryModel));
            createdCategory.Name = createdCategoryName;
        }

        /// <summary>
        /// Deletes the category
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            createdCategory.CategoryModel.Delete();
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Create Subcategory in Category '{0}'", parentCategory);
        }
    }
}
